package com.example.wallet.controller;

import com.example.wallet.pojo.Result;
import com.example.wallet.service.IWalletService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "钱包")
@Slf4j
@RestController
@RequestMapping("/wallet")
public class WalletController {
    @Autowired
    private IWalletService walletService;

    @ApiOperation("余额")
    @PostMapping("/query")
    @ApiImplicitParam(name = "userId", value = "用户ID", required = true, defaultValue = "1")
    public Result query(@RequestParam int userId) {
        return walletService.query(userId);
    }

    @ApiOperation("充值")
    @PostMapping("/topUp")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户ID", required = true,
                    defaultValue = "1"),
            @ApiImplicitParam(name = "money", value = "充值金额", required = true,
                    defaultValue = "100")
    })
    public Result topUp(@RequestParam int userId, @RequestParam int money) {
        return walletService.topUp(userId, money);

    }

    @ApiOperation("消费")
    @PostMapping("/consume")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户ID", required = true,
                    defaultValue = "1"),
            @ApiImplicitParam(name = "money", value = "消费金额", required = true,
                    defaultValue = "100")
    })
    public Result consume(@RequestParam int userId, @RequestParam double money) {
        return walletService.consume(userId, money);
    }

    @ApiOperation("退款")
    @PostMapping("/refund")
    @ApiImplicitParam(name = "orderId", value = "订单ID", required = true)
    public Result refund(@RequestParam int orderId) {
        return walletService.refund(orderId);
    }

    @ApiOperation("明细")
    @ApiImplicitParam(name = "userId", value = "用户ID", required = true,
            defaultValue = "1")
    @PostMapping("/details")
    public Result details(@RequestParam int userId) {
        return walletService.details(userId);
    }


}
